package main

import "fmt"

var(
	//一堆姓氏
	familiyNames = []string{"赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "楚", "魏", "蒋", "沈", "韩", "杨", "张", "欧阳"}
	//一堆名字结尾
	firstNames   = []string{"金", "木", "水", "火", "土", "风", "霜", "雨", "雪", "山", "石", "田", "土", "木", "禾", "米", "竹", "天", "地", "日", "月", "春", "夏", "秋", "冬"}

	//姓氏的辈分，姓氏做键，该姓氏的辈分切片做值
	generationalNameMap = make(map[string] []string )
)

/*
包的初始化函数，会执行在main函数之前
此处实现给不同的姓氏添加不同的辈分切片
*/
func init() {
	fmt.Println("util init")
	for _, ln := range familiyNames {
		if ln != "欧阳" {
			//为其它姓氏添加辈分
			generationalNameMap[ln] = []string{"飞", "前", "茂", "百", "方", "书", "生", "无", "一", "用"}
		}else{
			//为欧阳姓添加辈分
			generationalNameMap[ln] = []string{"宗", "的", "永", "其", "光"}
		}
	}
	//fmt.Println(generationalNameMap)
}

func GetRandomName() (name string) {

	//随机获取一个姓氏
	familyName := familiyNames[GetRandomInt(0, len(familiyNames)-1)]

	//查map获得该形式的所有辈分，随机选择一个作为中间字
	//fmt.Println(familyName, generationalNameMap[familyName])
	middleName := generationalNameMap[familyName][GetRandomInt(0, len(generationalNameMap[familyName])-1)]

	//随机抽取一个名字
	firstName := firstNames[GetRandomInt(0, len(firstNames)-1)]

	//拼接返回
	return familyName + middleName + firstName
}